// pages/yuyue/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    var that = this;
    wx.request({
      url: app.globalData.headurl + '/Lfdappoint/selectLfdappointByOpenid',
      data: {
        openid: app.globalData.openid
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (re) {
        that.setData({
          lfdappointlist: re.data.reverse() 
        })

      }
    })



  },

  toupdate: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    console.log("id:"+id+" status:"+status)
    wx.request({
      url: app.globalData.headurl + '/Lfdappoint/updateLfdappoint',
      data: {
        id: id,
        status:status
      },
      method: "POST",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=utf-8",
        //token: app.globalData.token
      },
      success: function (re) {
        wx.showToast({
          title: '操作成功',
        })
        that.onLoad();

      }
    })

  },

  tocomment: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var lid = e.currentTarget.dataset.lid;
    wx.navigateTo({
      url: '../comment/index?id=' + id + '&lid=' + lid,
    })
  },

  // 返回美发店详情
  backlfd:function(e){
    var sid = e.currentTarget.dataset.sid;
    wx.navigateTo({
      url: '../appointments/appointments?id=' + sid ,
    })
  },
  delappoint:function(e){
    var id  = e.currentTarget.dataset.id;
    console.log("删除订单",e.currentTarget.dataset.id)
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
            // 用户点击了确定 可以调用删除方法了
            wx.request({
              url: app.globalData.headurl + '/hLfdappoint/deleteLfdappoint',
              data: {
                id:id
              },
              method: "POST",
              header: {
                "content-type": "application/x-www-form-urlencoded;charset=utf-8",
                //token: app.globalData.token
              },
              success: function (r) {
                wx.showToast({
                  title: '删除成功',
                  duration:1200,
                })
                wx.switchTab({
                  url: '../order/index',
                })
              }
            })
          } else if (sm.cancel) {
            console.log('用户点击取消')
          }
        }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   this.onLoad();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})